Skip to content

test: unit tests for string-utils and date-utils - #465

Draft
quantcode-agent[bot] wants to merge 1 commit into
mainfrom
quantcode/job-50e7e8a5
Draft

quantcode-agent[bot] wants to merge 1 commit into
mainfrom
quantcode/job-50e7e8a5

Conversation

@quantcode-agent

Copy link
Copy Markdown

Summary

  • Extends test/string-utils.test.ts and test/date-utils.test.ts so every exported function has tests: capitalize, reverse, slugify, wordCount, truncate, formatRelative, isSameDay and addDays. The tests cover normal cases and edge cases.
  • Fixes three source bugs that the tests exposed:
    • truncate was not implemented. It now cuts at a word boundary, counts the ... toward maxLength, hard-cuts when there is no usable boundary, and handles a maxLength of 3 or less.
    • wordCount split on single spaces. It now trims the input and splits on any run of whitespace.
    • formatRelative used Math.floor for days, so 36h showed as "1 day ago". It now uses Math.round, so 36h shows as "2 days ago", which is what the existing test expects.
  • The date tests no longer depend on the timezone. They now build dates with new Date(y, m, d) instead of parsing UTC date-only strings, which failed in America/* timezones.

Test results

  • bun test test/string-utils.test.ts test/date-utils.test.ts: 65 pass, 0 fail. Checked under UTC, America/Los_Angeles, America/New_York, Australia/Sydney, Pacific/Kiritimati and Pacific/Pago_Pago.
  • bunx tsc --noEmit passes.
  • The full suite still has 10 failures, in calculator, validator and task-manager. The same 10 fail on main, and those files were out of scope, so I left them alone.

Assumptions

  • Some existing tests failed because the source was wrong, not the tests. "Ensure the new tests pass" was read as permission to fix the source in the two files in scope.
  • The existing tests define the intended behaviour, for example 36h → "2 days ago", plus the TODO spec for truncate.
  • Known limitation, left as is: truncate(" hello", 7) returns " ...", because when the first maxLength - 3 characters are all spaces the fallback keeps them. The length limit still holds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants